struct RAND_STU_CONFIG {
	bool doUseNumber;
	int iNumMin;
	int iNumMax;
};

int DefToRandStuConfig() {
	FILE *pCfg=fopen(RAND_STU_CONFIG_FILENAME,"w");
	if(pCfg==nullptr) {
		return -1;
	}
	fprintf(pCfg,
	        "doUseNumber=0\n\
iNumMin=0\n\
iNumMax=60");
	fclose(pCfg);
	return 0;
}
int ReadRandStuConfig(RAND_STU_CONFIG *cfg) {
	FILE *pCfg=fopen(RAND_STU_CONFIG_FILENAME,"r");
	if(pCfg==nullptr) {
		fclose(pCfg);
		DefToRandStuConfig();
		pCfg=fopen(RAND_STU_CONFIG_FILENAME,"r");
	}
	fscanf(pCfg,
	       "doUseNumber=%d\n\
iNumMin=%d\n\
iNumMax=%d"
	       ,&cfg->doUseNumber,&cfg->iNumMin,&cfg->iNumMax);
	fclose(pCfg);
	return 0;
}
int WriteRandStuConfig(RAND_STU_CONFIG cfg) {
	FILE *pCfg=fopen(RAND_STU_CONFIG_FILENAME,"w");
	if(pCfg==nullptr) {
		return -1;
	}
	fprintf(pCfg,
	        "doUseNumber=%d\n\
iNumMin=%d\n\
iNumMax=%d",cfg.doUseNumber,cfg.iNumMin,cfg.iNumMax);
	fclose(pCfg);
	return 0;
}

struct CLASS_NOTIFICATION_CONFIG {
	char szContent[500];
	int iSizeMode;
	int iColor; 
	bool bBold;
};

int DefToNotificationConfig(){
	FILE *pcf=fopen(CLASS_NOTIFICATION_CONFIG_FILENAME,"w");
	if(pcf==nullptr){
		return -1;
	}
	fprintf(pcf,"iSizeMode=2\nbBold=1\niColor=0\n###");
	fclose(pcf);
	return 0;
}

int WriteNotificationConfig(CLASS_NOTIFICATION_CONFIG cncfg){
	FILE *pcf=fopen(CLASS_NOTIFICATION_CONFIG_FILENAME,"w");
	if(pcf==nullptr){
		return -1;
	}
	fprintf(pcf,"iSizeMode=%d\nbBold=%d\niColor=%d\n###\n%s",
	cncfg.iSizeMode,cncfg.bBold,cncfg.iColor,cncfg.szContent);
	fclose(pcf);
	return 0;
}
int ReadNotificationConfig(CLASS_NOTIFICATION_CONFIG *cfg) {
	FILE *pCfg=fopen(CLASS_NOTIFICATION_CONFIG_FILENAME,"r");
	if(pCfg==nullptr) {
		fclose(pCfg);
		DefToNotificationConfig();
		pCfg=fopen(CLASS_NOTIFICATION_CONFIG_FILENAME,"r");
	}
	int r=fscanf(pCfg,
	       "iSizeMode=%d\nbBold=%d\niColor=%d\n###\n"
	       ,&cfg->iSizeMode,&cfg->bBold,&cfg->iColor);
	if(r!=3){
		DefToNotificationConfig();
		return -1;
	}
	int i=0;
	strcpy(cfg->szContent,"\0");
	while(!feof(pCfg)&&i<=199) {
		cfg->szContent[i]=getc(pCfg);
		if(cfg->szContent[i]=='\n'){
			cfg->szContent[i]='\r';
			i++;
			cfg->szContent[i]='\n';
		}
		i++;
	}
	cfg->szContent[i-1]='\0';
	fclose(pCfg);
	return 0;
}

